package com.imooc.socialecom.controller;

import com.imooc.socialecom.base.JsonReturnType;
import com.imooc.socialecom.pojo.MessageInfo;
import com.imooc.socialecom.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @RequestMapping(value = "/create", method = {RequestMethod.GET, RequestMethod.POST})
    public JsonReturnType create(@RequestBody MessageInfo messageInfo) throws IOException {
        messageInfo = messageService.postMessage(messageInfo);
        return JsonReturnType.createType(messageInfo);
    }

    @RequestMapping(value = "/get", method = {RequestMethod.GET})
    public JsonReturnType get(@RequestParam(name = "id") String id) throws IOException {
        return JsonReturnType.createType(messageService.getMessage(id));
    }


}
